import { find } from "../../api/customer";
import { find as groupFind } from "../../api/group";
import { datetime } from "../../utils/util";
Page({

    data: {
        id: null,
        detail: {},
        statusName: '',
        natureName: '',
        typeName: '',
        groupName:'',
        check: false,
        type: null,
    },
    onLoad(options) {
        this.data.id = options.id;
        this.setData({
            id:this.data.id 
        })
    },
    onShow(){
        this.getCustomerInfo(this.data.id);
    },
    getCustomerInfo(id) {
        find(id).then(res => {
            console.log(res);
            this.data.type = res.data.customer.type;
            this.setData({
                detail: res.data.customer,
                [`detail.createDate`]: datetime(res.data.customer.createDate)
            })
            this.formatState(res.data.customer.status);
            this.formatNature(res.data.customer.nature);
            this.formatType(res.data.customer.type);
            this.formatGroup();
        })
    },

    formatState(status) {
        let statusName;
        if (status == 0) {
            statusName = '未认证'
        }
        if (status == 1) {
            statusName = '已认证'
        }
        if (status == 2) {
            statusName = '已驳回'
        }
        this.setData({
            statusName: statusName
        })
    },
    formatNature(nature) {
        let natureName;
        if (nature == 1) {
            natureName = '经纪人(个人)'
        }
        if (nature == 2) {
            naturesName = '法人企业'
        }
        this.setData({
            natureName: natureName
        })
    },
    formatType(type) {
        let typeName;
        if (type == 1) {
            typeName = '供应商'
        }
        if (type == 2) {
            typeName = '采购方'
        }
        this.setData({
            typeName: typeName
        })
    },
    formatGroup() {
        groupFind(this.data.detail.groupId).then(res => {
            console.log(res, 'gid');
            this.setData({
                groupName:res.data.group.name
            })
        })
    },

    checkMsg() {
        this.setData({
            check: true
        })
    },
    clear() {
        this.setData({
            check: false
        })
    },
    returnPage() {
        wx.navigateBack();
    },
    editChange() {
        this.data.detail.metaInfo.chemical
        wx.navigateTo({
            url: '/pages/pagesUser/companyInfo/attestation?sellearEdit=' + true
                + '&id=' + this.data.detail.id
                + '&customerType=' + this.data.type
                + '&name=' + this.data.detail.name
                + '&nature=' + this.data.detail.nature
                + '&group_id=' + this.data.detail.groupId
                + '&groupName=' + this.data.groupName
                + '&linkman=' + this.data.detail.linkman
                + '&phone=' + this.data.detail.phone
                + '&address=' + this.data.detail.address
                + '&license=' + this.data.detail.metaInfo.license
                + '&chemical=' + this.data.detail.metaInfo.chemical
                + '&wholesale=' + this.data.detail.metaInfo.wholesale
                + '&other=' + this.data.detail.metaInfo.other
                + '&licenseCode=' + this.data.detail.metaInfo.licenseCode

                + '&legalPersonCode=' + this.data.detail.metaInfo.legalPersonCode
                + '&legalPerson1=' + this.data.detail.metaInfo.legalPerson1
                + '&legalPerson2=' + this.data.detail.metaInfo.legalPerson2
                + '&accountLicense=' + this.data.detail.metaInfo.accountLicense
                + '&banknum=' + this.data.detail.metaInfo.banknum
                + '&bankname=' + this.data.detail.metaInfo.bankname
                + '&legalGrant=' + this.data.detail.metaInfo.legalGrant
        })
    }
})